package com.webshop.service;

import com.webshop.DataDao.AddressDao;
import com.webshop.JavaBean.Address;

import java.util.List;

public class AddressService {
    AddressDao ad = new AddressDao();

    /**
     * 返回用户的地址信息 list
     * @param name
     * @return
     */
    public List<Address> getUserAddress(String name) {
        return ad.addressInfo(name);
    }

    /**
     * 用户新增地址信息。
     * @param address
     * @return
     */
    public boolean addAddress(Address address) {
        try {
            ad.insertAddress(address);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    /**
     * 用户修改地址信息
     * @param address
     * @return
     */
    public boolean modifyAddressInfo(Address address) {
        try {
            ad.modifyInfo(address);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    /**
     * 用户删除地址信息。
     * @param ID
     * @return
     */
    public boolean deleteAddressInfo(String ID) {
        try {
            ad.deleteInfo(ID);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    /**
     * 返回用户指定的地址。
     * @param ID
     * @return
     */
    public Address selectAddress(String ID) {
        return ad.getChoiceAddress(ID);
    }
}
